package com.zxkj.domain.mapper;

import com.zxkj.domain.entity.SciDoc;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * Created by Administrator on 2017/7/12.
 */
public interface SciDocRepository extends JpaRepository<SciDoc, String> {

    @Query(value = "SELECT * FROM sci_doc WHERE ut = ?1 limit 1", nativeQuery = true)
    SciDoc findByUT(String ut);

    @Query("select s from SciDoc s where num>=:startNum and num<=:endNum")
    Page<SciDoc> findAll(@Param("startNum") Integer startNum, @Param("endNum") Integer endNum, Pageable pageable);

    @Query("select s from SciDoc s where num>=:startNum and num<=:endNum")
    List<SciDoc> findAll(@Param("startNum") Integer startNum, @Param("endNum") Integer endNum);

    @Query("select s from SciDoc s")
    Page<SciDoc> findAll(Pageable pageable);

    @Query(value = "select * from sci_doc ORDER BY num DESC limit 1", nativeQuery = true)
    SciDoc findMaxNum();

    @Query(value = "SELECT * FROM sci_doc WHERE pubyear >= ?1 AND pubyear <= ?2 ORDER BY pubyear", nativeQuery = true)
    List<SciDoc> findByPubYear(String startYear, String endYear);
}
